/*
 * Copyright (c) 2009.
 * nick@tmro.net
 */
package net.tmro.loko.ejb.dao;

/**
 * Created by IntelliJ IDEA.
 * User: nick
 * Date: Mar 24, 2009
 * Time: 5:17:26 PM
 * To change this template use File | Settings | File Templates.
 */
public interface Dao<K, E> {

    /**
     * Saves the entity into the persistent storage
     *
     * @param entity entity to save
     */
    void persist(E entity);

    /**
     * Deletes the entity
     *
     * @param entity entity to remove
     */
    void remove(E entity);

    /**
     * Searches the storage for an entity that has the id equal to the value passed in.
     *
     * @param id unique identifier of the entity
     * @return the entity if found or null if not found. Unlike the #getById this should not throw exceptions
     * @see #getById(Object)
     */
    E findById(K id);

    /**
     * Does the same as #findById but if the object is not found it throws and exception
     *
     * @param id unique identifier of the object to find
     * @return the entity. Implementations of the interface should be throwing specific exceptions
     */
    E getById(K id);
}